package com.sinopec.handdevice.presenter

import com.sinopec.basemodule.api.BaseModuleApi
import com.sinopec.basemodule.http.CommonObserver
import com.sinopec.basemodule.http.ExceptionEngine
import com.sinopec.basemodule.model.PackSpecsTypeModel
import com.sinopec.handdevice.contract.DailyInventoryListContract

/**
 * @author lwj
 * @ClassName: DailyInventoryListPresenter
 * @Description:  日常盘点-获取包装规格列表
 */
class DailyInventoryListPresenter(view: DailyInventoryListContract.View?) :
    DailyInventoryListContract.Presenter(view!!) {

    /**
     * 日常盘点-获取包装规格列表
     */
    override fun dailyInventoryList() {
        val resultObservable = BaseModuleApi.getPackSpecsType()
        toSubscribe(resultObservable,
            object : CommonObserver<List<PackSpecsTypeModel>>(mView.context) {
                override fun onNext(list: List<PackSpecsTypeModel>) {
                    mView.refreshUI(getData())
                }

                override fun onError(t: ExceptionEngine.ResponseThrowable) {
                    mView.refreshUI(getData())
                    //mView.showMessage(t.message)
                }
            })
    }

    /**
     * @author lwj
     * @Description:测试数据
     */
    private fun getData(): List<PackSpecsTypeModel> {
        val list: MutableList<PackSpecsTypeModel> = ArrayList()
        for (i in 1..9) {
            val model = PackSpecsTypeModel()
            model.packSpecsTypeId = i.toLong()
            model.packSpecsTypeName = "共享托盘$i"
            list.add(model)
        }
        return list
    }
}